package rolesystem.middle.managers;

import java.util.ArrayList;

import rolesystem.middle.utilityclasses.KnownEnvironment;
import rolesystem.middle.utilityclasses.PositionSq;
import rolesystem.middle.utilityclasses.Square;

public class KnownEnvironmentManager
{
	private static ArrayList<KnownEnvironment> knownEnvironmentList;
	
	private static KnownEnvironment mergedKnownEnvironment;
	
	
	static
	{
		knownEnvironmentList=new ArrayList<KnownEnvironment>();
		mergedKnownEnvironment=new KnownEnvironment();
	}
	
	public synchronized static Square getMergedKnownPosition(PositionSq position)
	{
		return mergedKnownEnvironment.getKnownPosition(position);
	}
	
	public synchronized static void setKnownEnvironments(int agent_id,KnownEnvironment data)
	{
		try 
		{
			knownEnvironmentList.set(agent_id, data);
		} catch (IndexOutOfBoundsException  e) 
		{
			DataOutputManager.printString(" ERROR");
		}
	}
	
	public synchronized static KnownEnvironment getKnownEnvironments(int agent_id)
	{
		try 
		{
			return knownEnvironmentList.get(agent_id);
		} catch (IndexOutOfBoundsException  e) 
		{
			return null;
		}
	}
	
	public synchronized static void mergeWithId(int id,KnownEnvironment data)
	{
		getKnownEnvironments(id).merge(data);	
	}
	
	public synchronized static void mergeKnownEnvironments()
	{
		for(int i=0;i<knownEnvironmentList.size();i++)
			mergedKnownEnvironment.merge(knownEnvironmentList.get(i));
	}
	
	
	public synchronized static void CreateKnownEnvironments(int id_count)
	{
		for(int i=0;i<id_count;i++)
		{
			knownEnvironmentList.add(i, new KnownEnvironment() );
		}
	}
	
	public synchronized static void ResetMergedKnownEnvironments()
	{
		mergedKnownEnvironment=new KnownEnvironment();
	}
	
}
